package com.hidt.shop.controller;

import com.hidt.shop.domain.Payment;
import com.hidt.shop.service.PaymentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author Fhy
 * @Title PaymentController
 * @Package com.hdit.shop.controller
 * @Description 支付详情请求处理类
 * @date 2021/1/20 16:55
 */
@Controller
@ResponseBody
public class PaymentController {
    @Autowired
    private PaymentService paymentService;

    /**
     * 方法描述: 添加支付详情
     * @author Fhy
     * @Date 2021/1/20 17:18
     * @params [payment]
     * @return java.util.Map
     */
    @RequestMapping("/addPayment")
    public Map addPayment(@RequestBody Payment payment) {
//        调用service接口
        String message = paymentService.addPayment(payment);
//        结果返回
        Map<String,String> callMap = new HashMap<>();
        callMap.put("message",message);
        return callMap;
    }

    /**
     * 方法描述: 删除支付详情
     * @author Fhy
     * @Date 2021/1/20 17:19
     * @params [map]
     * @return java.util.Map
     */
    @RequestMapping("/deletePayment")
    public Map deletePayment(@RequestBody Map<String,Integer> map) {
//        调用service接口
        String message = paymentService.deletePayment(map.get("payment_id"));
//        结果返回
        Map<String,String> callMap = new HashMap<>();
        callMap.put("message",message);
        return callMap;
    }

    /**
     * 方法描述: 修改支付详情
     * @author Fhy
     * @Date 2021/1/20 17:19
     * @params [map]
     * @return java.util.Map
     */
    @RequestMapping("/updatePayment")
    public Map updatePaymetn(@RequestBody Map<String,String> map) {
//        调用service接口
        int payment_id = Integer.parseInt(map.get("payment_id"));
        String payment_way = map.get("payment_way");
        String message = paymentService.updatePayment(payment_id,payment_way);
//        结果返回
        Map<String,String> callMap = new HashMap<>();
        callMap.put("message",message);
        return callMap;
    }

    /**
     * 方法描述: 查找所有支付详情
     * @author Fhy
     * @Date 2021/1/20 17:19
     * @params []
     * @return java.util.List<com.hidt.shop.domain.Payment>
     */
    @RequestMapping("/findAllPayment")
    public List<Payment> findAllPayment() {
//        调用service接口
        List<Payment> paymentList = paymentService.findAllPayment();
//        结果返回
        return paymentList;
    }

    /**
     * 方法描述: 通过id查找对应支付方式
     * @author Fhy
     * @Date 2021/1/20 17:26
     * @params [map]
     * @return com.hidt.shop.domain.Payment
     */
    @RequestMapping("/findOnePaymentById")
    public Payment findOnePaymentById(@RequestBody Map<String,Integer> map) {
        Payment payment = paymentService.findOnePaymentById(map.get("payment_id"));
        return payment;
    }
}
